<template>
  <div>
    <div class="block suozaichengshi">
      <el-cascader
        :placeholder="city"
        :options="cityList"
        :props="Params"
        @change="handleChange"
        filterable
      ></el-cascader>
    </div>
  </div>
</template>



<style scoped>
</style>

<script>
export default {
  props:['setCity'],
  data() {
    return {
      selectCity:'',
      Params: {
        label: 'cname',
        value: 'cname',
        children: 'child',
        expandTrigger: 'hover',
      },
      city: this.setCity,
      cityList: [],
    };
  },
  methods: {
    handleChange(arr) {
      //console.log('城市选择', arr);
      var str = '';
      for (var i = 0; i < arr.length; i++) {
        str += arr[i] + '/';
      }
      //去掉最后一个逗号(如果不需要去掉，就不用写)
      if (str.length > 0) {
        str = str.substr(0, str.length - 1);
      }

      this.city = str;
    },
    //获取省份
    getcityList() {
      var that = this;
      this.$axios
        .get(this.$api + "//api/common/globalcityselect")
        .then(function (response) {
          that.cityList = response.data.data;
          //console.log("cityList", that.cityList);
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },
  mounted() {
    console.log('组上的城市', this.city);
    this.getcityList();
  },
  components: {
  },
};
</script>
